package com.cntv.lifecycledemo.kotlin

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.cntv.lifecycledemo.R
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        chronometer.visibility = View.GONE
        textView.text = "查看Log"
        lifecycle.addObserver(MyObserver())//只需添加需要感知生命周期的观察者即可

        button.setOnClickListener {
            var state = lifecycle.currentState.name
            Log.i("mhyLog当前", state)
            textView.text = state
        }

        button2.setOnClickListener {
            finish()
        }

    }

}
